<template>
  <el-carousel :interval="4000" type="card" height="200px">
    <el-carousel-item v-for="item in imgList" :key="item">
      <img :src="item.src" style="height: 400px;width: 100%;">
    </el-carousel-item>
  </el-carousel>
  <div class="gexing">
    <h4>补贴</h4>
    <div class="items">
      <div class="item" v-for="(item, index) in tableData" :key="index">
        <el-card :body-style="{ padding: '0px' }">
          <div style="padding: 14px" @click="handleEdit(item.ID)">
            <!--            ../../assets/img/applyList.png-->
            <!--          <router-link to="#">-->
            <!--            <img :src="item.picUrl" class="image" />-->
            <!--          </router-link>-->
            <img :src="item.subsidies_image" style="height:300px;width:300px"/><br>
            <span>补贴名称： {{ item.subsidy_name }}</span><br>
            <span>补贴金钱： {{ item.money }}</span><br>
            <span>补贴数量： {{ item.amount }}</span><br>
            <span>补贴描述： {{ item.describe }}</span><br>
          </div>
        </el-card>
      </div>
    </div>
  </div>
  <el-pagination
      v-model:currentPage="currentPage"
      :page-sizes="[3, 5, 10, 20]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="useSizeChange"
      @current-change="useCurrentChange"
  >
  </el-pagination>
  <rsSubsidy :editProductVisible="editProductVisible" :sId="sId" @onCloseEditDialog="closeEditDialogVisible" v-if="editProductVisible === true "></rsSubsidy>
</template>

<script>
import axios from "axios";
import {reactive, onMounted, toRefs} from "vue";
import rsSubsidy from  "../front_desk/ReservationSubsidy.vue"
function loaData(state){
  const params = {
    page:state.currentPage,
    limit:state.pageSize,
    search_content:state.searchContent
  }
  axios.get("/api/subsides", {params},).then((res) => {
    state.tableData = res.data.data.res.data
    state.total = res.data.data.res.total //总记录数
  })
}
//监听pageSize改变的事件
function useHandleSizeChange(state){
  const useSizeChange = (pageSize) => {
    console.log(pageSize)
    state.pageSize = pageSize
    loaData(state)
  }
  return {
    useSizeChange
  }
}
//监听当前页面切换的事件
function useHandleCurrentPage(state){
  const useCurrentChange = (page) => {
    console.log(page)
    state.currentPage = page
    loaData(state)
  }
  return {
    useCurrentChange,
  }
}
//申请详情
function useEdit(state){
  const handleEdit = (index) => {
    state.editProductVisible = true;
    state.sId = index
  }
  return {
    handleEdit
  }
}
export default {
  name: "FrontSubsidy",
  components:{
    rsSubsidy
  },
  setup(){
    const state = reactive({
      tableData: [],
      dialogVisible: false,//控制新增的窗口
      editProductVisible: false,//控制编辑的窗口
      total: 0,
      currentPage: 1,
      pageSize: 4,
      searchContent: "",//模糊搜索的内容
      sId: 0,
      imgList: [
        {
          name: "lj",
          src: new URL('../../assets/img/slideshow/01.jpg', import.meta.url).href,
          title: "这是lj.png"
        },
        {
          name: "logo",
          src: new URL('../../assets/img/slideshow/02.jpg', import.meta.url).href,
          title: "这是logo.png"
        },
        {
          name: "bg",
          src: new URL('../../assets/img/slideshow/03.jpg', import.meta.url).href,
          title: "这是bg.png"
        },
        {
          name: "sadmas",
          src: new URL('../../assets/img/slideshow/04.jpg', import.meta.url).href,
          title: "这是sadmas.png"
        }
      ]
    });
    const url = import.meta.env.VITE_APP_URL
    onMounted(() => {
      loaData(state)
    });
    //关闭编辑用户
    const closeEditDialogVisible = (visible) => {
      loaData(state)
      state.editProductVisible = visible;
    }
    return {
      ...toRefs(state),
      ...useHandleSizeChange(state),
      ...useHandleCurrentPage(state),
      ...useEdit(state),
      closeEditDialogVisible
    }
  }
}
</script>

<style scoped>
.items {
  display: flex;
  /*flex-wrap属性，wrap(包裹)根据大小设置一行放多少个，nowrap,都放一行 */
  flex-wrap: wrap;
  justify-content: space-around;
  /* position: relative; */
}
.item {
  position: relative;
  width: 18%;
}
.aa {
  margin-left: 50px;
  margin-right: 50px;
}
.img-wrap {
  width: 200px;
  height: 200px;
  background-color: #409eff;
  font-size: 10px;
  margin-top: 20px;
}
.img-wrap img {
  width: 100%;
}

.el-carousel__item h3 {
  color: #475669;
  font-size: 18px;
  opacity: 0.75;
  line-height: 300px;
  margin: 0;
  text-align: center;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}

</style>